# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=jp2-pixbuf-loader
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.0.2
pkgrel=1
pkgdesc="JPEG2000 GDK Pixbuf Loader library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://notabug.org/necklace/jp2-pixbuf-loader"
license=(LGPL2.1)
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-meson")
depends=("${MINGW_PACKAGE_PREFIX}-openjpeg2"
         "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2")
source=("${_realname}-${pkgver}.tar.gz::https://notabug.org/necklace/jp2-pixbuf-loader/archive/${pkgver}.tar.gz"
        "0001-meson-support-installing-to-a-different-prefix.patch")
sha256sums=('c5f33352fdd96309d747205deef7071c44093f4720f17674b60afe2fd3c37b88'
            '8f2084bc6e41743f8afb955c276f8793de1ae1485e749c767bd5c1a5869a123f')

prepare() {
  cd "${srcdir}/${_realname}"

  # https://notabug.org/necklace/jp2-pixbuf-loader/pulls/4
  patch -p1 -i "${srcdir}"/0001-meson-support-installing-to-a-different-prefix.patch
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  meson \
    --prefix=${MINGW_PREFIX} \
    --wrap-mode=nodownload \
    --auto-features=enabled \
    --buildtype=plain \
    "../${_realname}"

  meson compile
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  DESTDIR="${pkgdir}" meson install

  install -Dm644 "${srcdir}/${_realname}/LICENSE.txt" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.txt"
}
